package com.fxsh168.server.activity;

import android.Manifest;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.fxsh168.server.R;
import com.fxsh168.server.base.CheckPermissionsActivity;
import com.fxsh168.server.entitys.RegiYZMCG;
import com.fxsh168.server.interfaces.Constant;
import com.fxsh168.server.otherviews.SelectPicPopupWindow;
import com.fxsh168.server.utils.GetLastZF;
import com.fxsh168.server.utils.GetPhotoImgPath;
import com.fxsh168.server.utils.ImgDealUtils;
import com.fxsh168.server.utils.LProgressDialog;
import com.fxsh168.server.utils.PopInfo;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import cn.finalteam.rxgalleryfinal.RxGalleryFinalApi;
import cn.finalteam.rxgalleryfinal.ui.RxGalleryListener;
import cn.finalteam.rxgalleryfinal.ui.base.IRadioImageCheckedListener;
import cn.finalteam.rxgalleryfinal.utils.Logger;
import cn.finalteam.rxgalleryfinal.utils.MediaScanner;
import okhttp3.Call;

public class ReginPhotoActivity extends CheckPermissionsActivity implements View.OnClickListener {
    private static final int PORTRAITCODE = 1;
    private static final int JIASHIZPOSITIONCODE = 2;
    private static final int XINGSHIZPOSITIONCODE = 3;
    private static final int PAIZPOSITIONCODE = 4;
    private static final int CARPOSITIONCODE = 5;
    private static final int IDIMG1POSITIONCODE = 6;
    private static final int IDIMG2POSITIONCODE = 7;
    private static final int IDRENCAR = 8;
    private static final int IDBAO = 9;
    private static final int IDQIANG = 10;
    int takePhoto;
    private static final String PORTRAITCODE2NAME = "PORTRAITCODE2NAME";
    private static final String JIASHIZPOSITIONCODE2NAME = "JIASHIZPOSITIONCODE2NAME";
    private static final String XINGSHIZPOSITIONCODE2NAME = "XINGSHIZPOSITIONCODE2NAME";
    private static final String PAIZPOSITIONCODE2NAME = "PAIZPOSITIONCODE2NAME";
    private static final String CARPOSITIONCODE2NAME = "CARPOSITIONCODE2NAME";
    private static final String IDIMG1POSITIONCODE1NAME = "IDIMG1POSITIONCODE1NAME";
    private static final String IDIMG2POSITIONCODE2NAME = "IDIMG2POSITIONCODE2NAME";
    private static final String IDSRENCARICON = "IDSRENCARICON";
    private static final String IDBAOXIANPHOTO = "BAOXIANPHOTO";
    private static final String IDQIANGXIANPHOTO = "IDQIANGXIANPHOTO";


    // 裁剪后图片的宽(X)和高(Y),480 X 480的正方形。
    private String mGetName, mGetIDNumber, mGetCarBrand, mGetCarNumber, mGetCarCorlor;
    private ImageView mPortrait, mJiashizpositive, mXingshizpositove, mPaizpositive, mCarpositive, imRenCar, imBao, imQiang;
    private Bitmap photo;
    private File mFile;
    private String mFileNamePath, mPhotoName, mGetJiaShiZheng, mGetXingShiZheng;
    private ImageView mIDImg1, mIDImg2;
    private File pORTRAITFile, jIASHIZPFile, xINGSHIZPFile, pAIZPFile, cARPOTFile,
            iDIMG1PFile, iDIMG2PFile, iDIMGRRENCARFILES, iDBaoFiles, iDQiangFiles;
    private String mPortraitName, mJIASHIZPName, mXINGSHIZName, mPAIZPName, mCARPOTName;
    private String mIDIMG1PName, mIDIMG2PName, mPhone, mRenCAR, MBao, MQiang;
    Button mBtnTiJiao;
    private String phone, mPass, mYaoText, mChooseWhol;
    SelectPicPopupWindow menuWindow;
    File tempFile;
    ImageView animation_ivLogin;
    int status = 0;
    PopInfo popInfo;
    /******************************新的图片上传工具*****************************************/
    private int state = 1;//1-6分别对应6个图片地址
    private String mImage1,mImage2,mImage3,mImage4,mImage5,mImage6;//裁剪之后的图片
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recruitment_driver2);
        phone = getIntent().getStringExtra("phone");
        mPass = getIntent().getStringExtra("mPass");
        mYaoText = getIntent().getStringExtra("yao");
        mChooseWhol = getIntent().getStringExtra("choosewho");
        Log.e("tag", "照片页面" + phone + mPass);
        initView();
    }

    @Override
    public void requestPermissionResult(boolean allowPermission) {
        if (allowPermission) {
            showToast("权限申请成功");
        } else {
            showToast("请前往设置中心打开相机，相册权限");
        }
    }
    private void initView() {
        pORTRAITFile = new File("/sdcard/Image/" + "PORTRAITCODE2NAME" + ".png");
        mPortraitName = GetLastZF.getLatZF("/sdcard/Image/" + "PORTRAITCODE2NAME" + ".png", "/");//头像

        jIASHIZPFile = new File("/sdcard/Image/" + "JIASHIZPOSITIONCODE2NAME" + ".png");
        mJIASHIZPName = GetLastZF.getLatZF("/sdcard/Image/" + "JIASHIZPOSITIONCODE2NAME" + ".png", "/");//驾驶证

        xINGSHIZPFile = new File("/sdcard/Image/" + "XINGSHIZPOSITIONCODE2NAME" + ".png");
        mXINGSHIZName = GetLastZF.getLatZF("/sdcard/Image/" + "XINGSHIZPOSITIONCODE2NAME" + ".png", "/");//行驶证

        pAIZPFile = new File("/sdcard/Image/" + "PAIZPOSITIONCODE2NAME" + ".png");
        mPAIZPName = GetLastZF.getLatZF("/sdcard/Image/" + "PAIZPOSITIONCODE2NAME" + ".png", "/");//牌照

        cARPOTFile = new File("/sdcard/Image/" + "CARPOSITIONCODE2NAME" + ".png");
        mCARPOTName = GetLastZF.getLatZF("/sdcard/Image/" + "CARPOSITIONCODE2NAME" + ".png", "/");//车辆照

        iDIMG1PFile = new File("/sdcard/Image/" + "IDIMG1POSITIONCODE1NAME" + ".png");
        mIDIMG1PName = GetLastZF.getLatZF("/sdcard/Image/" + "IDIMG1POSITIONCODE1NAME" + ".png", "/");//身份证正

        iDIMG2PFile = new File("/sdcard/Image/" + "IDIMG2POSITIONCODE2NAME" + ".png");
        mIDIMG2PName = GetLastZF.getLatZF("/sdcard/Image/" + "IDIMG2POSITIONCODE2NAME" + ".png", "/");//身份证反

        iDIMGRRENCARFILES = new File("/sdcard/Image/" + "IDSRENCARICON" + ".png");
        mRenCAR = GetLastZF.getLatZF("/sdcard/Image/" + "IDSRENCARICON" + ".png", "/");   //人车

        iDBaoFiles = new File("/sdcard/Image/" + "BAOXIANPHOTO" + ".png");
        MBao = GetLastZF.getLatZF("/sdcard/Image/" + "BAOXIANPHOTO" + ".png", "/");   //保险

        iDQiangFiles = new File("/sdcard/Image/" + "IDQIANGXIANPHOTO" + ".png");    //强险
        MQiang = GetLastZF.getLatZF("/sdcard/Image/" + "IDQIANGXIANPHOTO" + ".png", "/");
        animation_ivLogin = (ImageView) findViewById(R.id.animation_ivLogin);
        LinearLayout liRenCar = (LinearLayout) findViewById(R.id.liRenCar);
        LinearLayout liSF = (LinearLayout) findViewById(R.id.liSF);
        LinearLayout liSZ = (LinearLayout) findViewById(R.id.liSZ);
        LinearLayout liZhengChe = (LinearLayout) findViewById(R.id.liZhengChe);
        LinearLayout liZhengPai = (LinearLayout) findViewById(R.id.liZhengPai);
        LinearLayout liXingShi = (LinearLayout) findViewById(R.id.liXingShi);
        LinearLayout liJiaShi = (LinearLayout) findViewById(R.id.liJiaShi);
        LinearLayout liPhotoHeader = (LinearLayout) findViewById(R.id.liPhotoHeader);

        //获取上一页传递过来的值
        SharedPreferences sp = getSharedPreferences(Constant.RECRUITDRIVCLSS, MODE_PRIVATE);
        mGetName = sp.getString("getName", "").trim();
        mGetIDNumber = sp.getString("getIDNumber", "").trim();
        mGetCarBrand = sp.getString("getCarBrand", "").trim();
        mGetCarNumber = sp.getString("getCarNumber", "").trim();
        mGetCarCorlor = sp.getString("getCarCorlor", "").trim();
        mGetJiaShiZheng = sp.getString("getJiaShiZheng", "").trim();
        mGetXingShiZheng = sp.getString("getXingShiZheng", "").trim();
//        初始化
        imQiang = (ImageView) findViewById(R.id.imQiangXian);
        imBao = (ImageView) findViewById(R.id.imBaoXian);
        imRenCar = (ImageView) findViewById(R.id.imRenCar);
        mPortrait = (ImageView) findViewById(R.id.portrait);
        mJiashizpositive = (ImageView) findViewById(R.id.jiashizpositive);
        mXingshizpositove = (ImageView) findViewById(R.id.xingshizpositove);
        mPaizpositive = (ImageView) findViewById(R.id.paizpositive);
        mCarpositive = (ImageView) findViewById(R.id.carpositive);
        mIDImg1 = (ImageView) findViewById(R.id.IDImg1);
        mIDImg2 = (ImageView) findViewById(R.id.IDImg2);
        mBtnTiJiao = (Button) findViewById(R.id.btnTiJiao);

//        点击监听
        imQiang.setOnClickListener(this);
        imBao.setOnClickListener(this);
        liRenCar.setOnClickListener(this);
        liSF.setOnClickListener(this);
        liSZ.setOnClickListener(this);
        liZhengChe.setOnClickListener(this);
        liZhengPai.setOnClickListener(this);
        liXingShi.setOnClickListener(this);
        liJiaShi.setOnClickListener(this);
        liPhotoHeader.setOnClickListener(this);
        mBtnTiJiao.setOnClickListener(this);
        //从登陆端获取电话号码
        SharedPreferences sp2 = getSharedPreferences(Constant.LOGINCLASS, MODE_PRIVATE);
        mPhone = sp2.getString("mPhone", "");
        RxGalleryListener
                .getInstance()
                .setRadioImageCheckedListener(
                        new IRadioImageCheckedListener() {
                            @Override
                            public void cropAfter(Object t) {
                                Toast.makeText(getBaseContext(), t.toString(), Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public boolean isActivityFinish() {
                                return false;
                            }
                        });
    }


    private void deletaPhoto(Uri mImageUri, String path) {
//         path = "/storage/emulated/0/DCIM/mdm.jpg"; //获取到的图片完整路径（例子）
        if (!TextUtils.isEmpty(path)) {
            Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            ContentResolver mContentResolver = ReginPhotoActivity.this.getContentResolver();
            String where = MediaStore.Images.Media.DATA + "='" + path + "'";
            //删除图片
            mContentResolver.delete(mImageUri, where, null);
            //发送广播
            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            File file = new File(path);
            Uri uri1 = Uri.fromFile(file);
            intent.setData(uri1);
            ReginPhotoActivity.this.sendBroadcast(intent);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.liSF:
                state = 3;
                RxGalleryFinalApi.openZKCamera(this);
                break;
            case R.id.liSZ:
                state = 2;
                RxGalleryFinalApi.openZKCamera(this);
                break;
            case R.id.liZhengChe:
                takePhoto = CARPOSITIONCODE;
                btnPortrat();
                break;
            case R.id.liZhengPai:
                state = 6;
                RxGalleryFinalApi.openZKCamera(this);
                break;
            case R.id.liXingShi:
                state = 5;
                RxGalleryFinalApi.openZKCamera(this);
                break;
            case R.id.liJiaShi:
                state = 4;
                RxGalleryFinalApi.openZKCamera(this);
                break;
            case R.id.liPhotoHeader:
                /*takePhoto = PORTRAITCODE;
                btnPortrat();*/
                state = 1;
                RxGalleryFinalApi.openZKCamera(this);
                break;
            case R.id.liRenCar:
                takePhoto = IDRENCAR;
                btnPortrat();
                break;
            case R.id.btnTiJiao:
                if (status == 0) {
                    status = 1;
                    btnTiJiao();
                } else {
                    mBtnTiJiao.setClickable(false);
                    popInfo = new PopInfo(ReginPhotoActivity.this, ReginPhotoActivity.this.findViewById(R.id.li_photo), "正在上传，请勿重复点击!", onShowClick);
                }
                break;
            case R.id.imBaoXian:
                takePhoto = IDBAO;
                btnPortrat();
                break;
            case R.id.imQiangXian:
                takePhoto = IDQIANG;
                btnPortrat();
                break;
        }
    }

    private View.OnClickListener onShowClick = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.teOk:
                    popInfo.dismiss();
                    break;
                default:
                    break;
            }
        }
    };

    //       修改头像

    public void btnPortrat() {
        //实例化SelectPicPopupWindow
        menuWindow = new SelectPicPopupWindow(ReginPhotoActivity.this, itemsOnClick);
        //显示窗口
        menuWindow.showAtLocation(ReginPhotoActivity.this.findViewById(R.id.li_photo), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); //设置layout在PopupWindow中显示的位置
    }

    //为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {
        public void onClick(View v) {
            menuWindow.dismiss();
            switch (v.getId()) {
                case R.id.buttonLocal:
                    requestPermission();
                    choseHeadImageFromGallery(takePhoto);
                    break;
                case R.id.buttonCamera:
                    requestPermission();
                    choseHeadImageFromCameraCapture(takePhoto);
                    break;
                default:
                    break;
            }
        }
    };

    //    权限
    protected String[] needContactsPermissions = {
            Manifest.permission.CAMERA};

    private void requestPermission() {
        if (!mayRequestPermission(needContactsPermissions)) {
            return;
        }
    }


    // 启动手机相机拍摄照片作为头像
    private void choseHeadImageFromCameraCapture(int requestCode1) {
        Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // 判断存储卡是否可用，存储照片文件
        if (hasSdcard()) {
            intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), getFileName(requestCode1))));
        }
        startActivityForResult(intentFromCapture, requestCode1);
    }


    public String getFileName(int requestCode1) {
        if (requestCode1 == 1) {
            return "1.jpg";
        } else if (requestCode1 == 2) {
            return "2.jpg";
        } else if (requestCode1 == 3) {
            return "3.jpg";
        } else if (requestCode1 == 4) {
            return "4.jpg";
        } else if (requestCode1 == 5) {
            return "5.jpg";
        } else if (requestCode1 == 6) {
            return "6.jpg";
        } else if (requestCode1 == 7) {
            return "7.jpg";
        } else if (requestCode1 == 8) {
            return "8.jpg";
        } else if (requestCode1 == 9) {
            return "9.jpg";
        } else if (requestCode1 == 10) {
            return "10.jpg";
        }
        return "";
    }


    // 从本地相册选取图片作为头像
    private void choseHeadImageFromGallery(int requestCode1) {
        Intent intent = new Intent(Intent.ACTION_PICK, null);
        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image//*");
        startActivityForResult(intent, requestCode1);
    }


    public void btnTiJiao() {
        Log.e(e,"myphoto"+pORTRAITFile);
        Log.e(e,"myphoto"+pORTRAITFile.toString().trim());
        if (TextUtils.isEmpty(mImage1)){
            status = 0;
            showToast("本人头像为空,请重新上传!");
            return;
        }
        if (TextUtils.isEmpty(mImage4)){
            status = 0;
            showToast("驾驶证正面照为空,请重新上传!");
            return;
        }
        if (TextUtils.isEmpty(mImage5)){
            status = 0;
            showToast("行驶证正面照为空,请重新上传!");
            return;
        }
        if (TextUtils.isEmpty(mImage2)){
            status = 0;
            showToast("身份证正面照为空,请重新上传!");
            return;
        }
        if (TextUtils.isEmpty(mImage3)){
            status = 0;
            showToast("身份证反面照为空,请重新上传!");
            return;
        }
        if (TextUtils.isEmpty(mImage6)){
            status = 0;
            showToast("牌照正面照为空,请重新上传!");
            return;
        }
        initTransDriverImfor();
    }

    private static final String e = "wwww";
    //提交进网络请求
    protected void initTransDriverImfor() {
        LProgressDialog.show(this,"正在上传图片,请耐心等待");
        /*参数：card       身份证
        username  姓名    carnum     车牌号码  brand     车辆匹配   carcolor  车辆颜色
        phone     手机号  myphoto    本人照片 driving    驾驶证照片 license   行驶证照片
        number    车牌照片 carphoto  车辆照片 drivingn   驾驶证号码 licensen  行驶证号码
        cardn     身份证正面
*/




        OkHttpUtils.post().addParams("phone", phone)
                .addParams("password", mPass)
                .addParams("routes", mChooseWhol)       //1为快车，4为专车
                .addParams("username", mGetName)
                .addParams("card", mGetIDNumber)
                .addParams("brand", mGetCarBrand)
                .addParams("carnum", mGetCarNumber)
                .addParams("carcolor", mGetCarCorlor)
                .addParams("drivingn", mGetJiaShiZheng)
                .addParams("licensen", mGetXingShiZheng)
//                .addParams("iid", mYaoText)
                .addFile("myphoto", mImage1.substring(mImage1.lastIndexOf("/") + 1), new File(mImage1))//头像
                .addFile("driving", mImage1.substring(mImage4.lastIndexOf("/") + 1), new File(mImage4))//驾驶证
                .addFile("license", mImage1.substring(mImage5.lastIndexOf("/") + 1), new File(mImage5))//行驶证
                .addFile("number", mImage1.substring(mImage6.lastIndexOf("/") + 1), new File(mImage6))//拍照
                .addFile("cardn", mImage1.substring(mImage2.lastIndexOf("/") + 1), new File(mImage2))//身份证正面
                .addFile("cardy", mImage1.substring(mImage3.lastIndexOf("/") + 1), new File(mImage3))//身份证反面
//                .addFile("group_photo", mRenCAR, iDIMGRRENCARFILES)
//                .addFile("insurance", MBao, iDBaoFiles)
//                .addFile("insurance2", MQiang, iDQiangFiles)
                .url(Constant.DRAIVERREGIN)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                showToast("连接不上服务器或信息填写不全!");
                Log.e("tag", "注册失败" + e);
                LProgressDialog.dismiss();
            }

            @Override
            public void onResponse(String response, int id) {
                if (response != null) {
                    LProgressDialog.dismiss();
                    Log.e("tag", "司机注册=" + response);
                    RegiYZMCG regiYZMCG = new Gson().fromJson(response, RegiYZMCG.class);
                    String code = regiYZMCG.getCode().trim();
                    if (code.equals(200 + "")) {
                        status = 0;
                        refreshUi(false, animation_ivLogin);
                        showToast("注册成功!");
                        startActivity(new Intent(ReginPhotoActivity.this, LoginActivity.class));
                        ReginPhotoActivity.this.finish();
                    } else if (code.equals(201 + "")) {
                        popInfo = new PopInfo(ReginPhotoActivity.this, ReginPhotoActivity.this.findViewById(R.id.li_photo), "非法请求!", onShowClick);
                        status = 0;
                        refreshUi(false, animation_ivLogin);
                    } else if (code.equals(204 + "")) {
                        popInfo = new PopInfo(ReginPhotoActivity.this, ReginPhotoActivity.this.findViewById(R.id.li_photo), "图片上传失败!", onShowClick);
                        status = 0;
                        refreshUi(false, animation_ivLogin);
                    } else if (code.equals(205 + "")) {
                        popInfo = new PopInfo(ReginPhotoActivity.this, ReginPhotoActivity.this.findViewById(R.id.li_photo), "资料上传失败!", onShowClick);
                        status = 0;
                        refreshUi(false, animation_ivLogin);
                    } else if (code.equals(206 + "")) {
                        popInfo = new PopInfo(ReginPhotoActivity.this, ReginPhotoActivity.this.findViewById(R.id.li_photo), "账号已存在，请登录", onShowClick);
                        status = 0;
                        refreshUi(false, animation_ivLogin);
                    } else if (code.equals(209 + "")) {
                        popInfo = new PopInfo(ReginPhotoActivity.this, ReginPhotoActivity.this.findViewById(R.id.li_photo), "注册失败", onShowClick);
                        status = 0;
                        refreshUi(false, animation_ivLogin);
                    } else if (code.equals(345 + "")) {
                        popInfo = new PopInfo(ReginPhotoActivity.this, ReginPhotoActivity.this.findViewById(R.id.li_photo), "已提交申请，请不要重复提交!", onShowClick);
                        status = 0;
                        refreshUi(false, animation_ivLogin);
                    }
                }
            }
        });
    }

    public static boolean hasSdcard() {
        String state = Environment.getExternalStorageState();
        if (state.equals(Environment.MEDIA_MOUNTED)) {
            // 有存储的SDCard
            return true;
        } else {
            return false;
        }
    }

    //从相册里面返回的结果
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (requestCode == RxGalleryFinalApi.TAKE_IMAGE_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            Log.i("------------","拍照OK，图片路径:" + RxGalleryFinalApi.fileImagePath.getPath());
            switch (state){
                case 1:
                    mImage1 = RxGalleryFinalApi.fileImagePath.getPath();
                    Glide.with(ReginPhotoActivity.this).load(mImage1).into(mPortrait);
                    break;
                case 2:
                    mImage2 = RxGalleryFinalApi.fileImagePath.getPath();
                    Glide.with(ReginPhotoActivity.this).load(mImage2).into(mIDImg1);
                    break;
                case 3:
                    mImage3 = RxGalleryFinalApi.fileImagePath.getPath();
                    Glide.with(ReginPhotoActivity.this).load(mImage3).into(mIDImg2);
                    break;
                case 4:
                    mImage4 = RxGalleryFinalApi.fileImagePath.getPath();
                    Glide.with(ReginPhotoActivity.this).load(mImage4).into(mJiashizpositive);
                    break;
                case 5:
                    mImage5 = RxGalleryFinalApi.fileImagePath.getPath();
                    Glide.with(ReginPhotoActivity.this).load(mImage5).into(mXingshizpositove);
                    break;
                case 6:
                    mImage6 = RxGalleryFinalApi.fileImagePath.getPath();
                    Glide.with(ReginPhotoActivity.this).load(mImage6).into(mPaizpositive);
                    break;
            }
            //刷新相册数据库
/*
            RxGalleryFinalApi.openZKCameraForResult(ReginPhotoActivity.this, new MediaScanner.ScanCallback() {
                @Override
                public void onScanCompleted(String[] strings) {
                    Log.i("------------>",String.format("拍照成功,图片存储路径:%s", strings[0]));

                    RxGalleryFinalApi.cropScannerForResult(ReginPhotoActivity.this, RxGalleryFinalApi.getModelPath(), strings[0]);//调用裁剪.RxGalleryFinalApi.getModelPath()为默认的输出路径
                }
            });
*/
        } else {
            Logger.i("失敗");
        }
    }


    private Bitmap getImg(String mSelectPath, String photoName) {
        Log.e("mSelectPath", "mSelectPath=" + mSelectPath);
        photo = ImgDealUtils.reSizeBitmap(mSelectPath, 800f, 480f);
        FileOutputStream fos = null;
        mFile = new File("/sdcard/Image/");
        if (!mFile.exists()) {
            mFile.mkdirs();// 创建文件夹
        }
        //文件路径
        mFileNamePath = "/sdcard/Image/" + photoName + ".png";
        //获取最后文件名
        mPhotoName = GetLastZF.getLatZF(mFileNamePath, "/");
        try {
            fos = new FileOutputStream(mFileNamePath);
            if (photo != null) {
                photo.compress(Bitmap.CompressFormat.PNG, 100, fos);
                return photo;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

}
